package brundfahrt

import java.util.Date;

class Communication implements Serializable{
	Person					contact
	Date					dateOfInvation = new Date() //when first contact was made
	Date					lastContact //when we last talked with sponsor - together with time
	Integer					probability //percentage that they will accept
	Date					nextContact //when we should contact them again - together with time
	Date					dateOfAnswer
	SponsorshipStatusEnum	confirmationStatus = SponsorshipStatusEnum.UNDECIDED//if sponsorship was confirmed

	static constraints = {
		contact(nullable: true)
		dateOfInvation(nullable: true)
		lastContact(nullable: true)
		probability(nullable: true, max: 100, min: 1)
		nextContact(nullable: true)
		dateOfAnswer(nullable: true,
			validator:{val, obj->
				//date of answer allowed only when confirmation status in accepted or refused
				if ((val && obj.confirmationStatus == SponsorshipStatusEnum.UNDECIDED) ||
					(!val && obj.confirmationStatus != SponsorshipStatusEnum.UNDECIDED))
					return false
			}
		)
		confirmationStatus(
			validator:{val, obj->
				//status can be UNDECIDED only when dateOf Answer is not filled
				if (val == SponsorshipStatusEnum.UNDECIDED && obj.dateOfAnswer){
					return false
				} else if (val != SponsorshipStatusEnum.UNDECIDED && !obj.dateOfAnswer){
					return false
				}
			}
		)
	}
	
}
